﻿function getSearchSongAdmin() {
    isShowUnapproved = $('#checkboxSelection').is(":checked");
    userSearchTextValue = $("#inputUserSearch").val();
    keywordSearchTextValue = $("#inputTextSearch").val();
    gotoSongAdminPage(1);
}

function gotoSongAdminPage(page) {
    $("#loaderIndicator").show();
    $("#searchContentDiv").fadeOut(200);
    $.ajax(
        {
            type: "POST",
            url: "/Admin/SongListPartial",
            data: { pageNumber: page, keyword: keywordSearchTextValue, username: userSearchTextValue, isOnlyUnapprove: isShowUnapproved },
            success: function (result) {
                $("#searchContentDiv").fadeIn(200);
                $("#searchContentDiv").html(result);
                $("#loaderIndicator").hide();
            },
            error: function (error) {
                alert(error);
            }
        });
}

function jumpToPage(pageElement, songId) {
    var pageNumber = $(pageElement).val();
    gotoCommentPage(pageNumber);
}

function lockSong(id, page, value) {
    $("#errorMessage").html("");
    $("#loaderIndicator").show();
    $("#searchContentDiv").fadeOut(200);
    $.ajax(
        {
            type: "POST",
            url: "/Admin/Lock",
            data: { pageNumber: page, keyword: keywordSearchTextValue, username: userSearchTextValue, songId: id, lockValue: value, isOnlyUnapprove: isShowUnapproved },
            success: function (result) {
                $("#searchContentDiv").fadeIn(200);
                $("#searchContentDiv").html(result);
                $("#loaderIndicator").hide();
            },
            error: function (error) {
                gotoSongAdminPage(id, 1);
                $("#errorMessage").html("Error");
            }
        });
}

function deleteSong(id, page) {
    $.msgbox("Are you sure that you want to permanently delete the selected element?", {
        type: "info",
        buttons: [
          { type: "submit", value: "Yes" },
          { type: "submit", value: "No" },
        ]
    }, function (result) {
        if (result == "Yes") {
            $("#errorMessage").html("");
            $("#loaderIndicator").show();
            $("#searchContentDiv").fadeOut(200);
            $.ajax(
                {
                    type: "POST",
                    url: "/Admin/DeleteSong",
                    data: { pageNumber: page, keyword: keywordSearchTextValue, username: userSearchTextValue, songId: id, isOnlyUnapprove: isShowUnapproved },
                    success: function (result) {
                        $("#searchContentDiv").fadeIn(200);
                        $("#searchContentDiv").html(result);
                        $("#loaderIndicator").hide();
                    },
                    error: function (error) {
                        gotoSongAdminPage(1);
                        $("#errorMessage").html("Error");
                    }
                });
        }
    });
}